package com.app.service;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.app.common.core.IBaseDAO;
import com.app.dao.DemoDAO;
import com.app.pojo.Demo;

/**
 * Description: service层 <br/>
 * Date: 2017年3月9日 上午11:52:17 <br/>
 * 
 * @author xuejianxin
 */
@Service("DemoService")
public class DemoService implements IDemoService {
	@Autowired
	private DemoDAO dao;

	@Override
	public IBaseDAO<Demo, String> getDao() {
		return dao;
	}

	// @Transactional(readOnly = false)
	public Integer save(Demo entity) {
		dao.save(entity);
		// System.out.println(1/0);
		// entity.setId(ID.get());
		// dao.save(entity);
		// saveBatchTest();
		// 测试事物
		// java.util.List<Demo> ds = queryForList(null);
		// ds.forEach(o -> System.out.println(o));
		return 1;
	}

	public Integer saveBatchTest() {
		List<Demo> list = IntStream.range(0, 1000).mapToObj(i -> {
			Demo d = new Demo();
			d.setId(String.format("%03d", i));
			d.setName("name" + i);
			return d;
		}).collect(Collectors.toList());

		return dao.saveBatch(list);
	}
}
